package easy;

public class Huiwenshu {

    public boolean isPalindrome(int x) {
        /*// 负数不为回文
        if (x < 0){
            return false;
        }

        // 将数字转化为字符串
        String str = String.valueOf(x);

        // 使用双指针法判断是否为回文
        int left = 0;
        int right = str.length() - 1;

        while (left < right) {
            if (str.charAt(left) != str.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;*/

        if (x < 0 || (x % 10 == 0 && x != 0)){
            return false;
        }

        int revertedNumber = 0;
        while (x > revertedNumber){
            revertedNumber = revertedNumber * 10 + x % 10;
            x /= 10;
        }
        return x== revertedNumber || x ==revertedNumber / 10;

    }
}


